<?php
  $due = array();
  $not_due = array();
  $date_today = time();
?>
<?php foreach($receivables as $receivable):?>
  <?php $due_date = strtotime($receivable['due_date']);?>
  <?php 
    if ($date_today>$due_date)
      $due[] = $receivable;
    else
      $not_due[] = $receivable;
  ?>
<?php endforeach;?>

<div class="module_title">
  <h2><?php echo $owner->getListName()?></h2>
  <h2>Statement of Account</h2>
</div>
<table class="form">
  <tr>
    <th>Customer Name:</th>
    <td><?php echo $contact->getListName()?></td>
  </tr>
  <tr>
    <th>Address:</th>
    <td><?php echo nl2br($contact->getCityAddress())?></td>
  </tr>
  <tr>
    <th>Phone:</th>
    <td><?php echo $contact->getPhone()?></td>
  </tr>
</table>
<hr/>
<h3>Receivables for period <?php echo date('m/d/Y',strtotime($date_from))?> to <?php echo date('m/d/Y',strtotime($date_to))?></h3>
<?php if(count($due)>0):?>
  <b>Invoices Due</b><br/>
  <?php include_partial('invoice_list',array('receivables'=>$due,))?>
  <br/>
<?php endif;?>
<?php if(count($not_due)>0):?>
  <b>Invoices Not Yet Due</b><br/>
  <?php include_partial('invoice_list',array('receivables'=>$not_due,))?>
  <br/>
<?php endif;?>
<?php if(count($cash_advances)>0):?>
  <h3>Cash Advances as of <?php echo date('m/d/Y')?></h3>
  <?php include_partial('cash_advances_list',array('cash_advances'=>$cash_advances,))?>
  <br/>
<?php endif;?>
<?php if(count($check_advances)>0):?>
  <h3>Check Advances as of <?php echo date('m/d/Y')?></h3>
  <?php include_partial('check_advances_list',array('check_advances'=>$check_advances,))?>
<?php endif;?>